//
//  kefuViewController.m
//  jypt_ios
//
//  Created by 千翼网络科技 on 2017/8/31.
//  Copyright © 2017年 xp. All rights reserved.
//

#import "kefuViewController.h"
#import "zaixiankefuTableViewController.h"
//#import "zhinanViewController.h"

@interface kefuViewController ()

@property (nonatomic,strong) UILabel *numLabel;
@property (nonatomic,strong) NSMutableDictionary *dataDic;

@end

@implementation kefuViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"客服";
    self.view.backgroundColor = getColor(@"eeeeee");
    [self requestData];
//    [self initView];
}

#pragma mark ------------------ requestData -------------------

- (void)requestData{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication]keyWindow] animated:YES];
    
    NSMutableDictionary *productParams = [[NSMutableDictionary alloc]init];
    [productParams setObject:[PublicFunction getConfigWithKey:@"token"] forKey:@"token"];
    
    [[MNetworkHandler sharedInstance]conURL:adminSafestcustomerService
                                networkType:NetWorkPOST
                                     params:nil
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   
                                   if ([[returnData objectForKey:@"code"]intValue] == 1) {
                                       
                                       [hud removeFromSuperview];
                                       
                                       _dataDic = [[NSMutableDictionary alloc]init];
                                       _dataDic = returnData[@"data"];
                                       NSLog(@"\n\n\n === %@",_dataDic);
                                       
                                       [self initView];
                                       
                                   }else{
                                       
                                       [hud removeFromSuperview];
                                       
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:1.0f];
                                       
                                   }
                                   
                               } failureBlock:^(NSError *error) {
                                   
                                   [hud removeFromSuperview];
                                   NSLog(@"%@",error);
//                                   [PublicFunction showAlert:nil message:@"没有连接网络" duration:1.0f];
                               }];
}

#pragma mark ------------------ init -------------------

- (void)initView{
    
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, scrWidth(), screenScale(164))];
    bgView.backgroundColor = getColor(@"ffffff");
    [self.view addSubview:bgView];
    
    ///
    
    UIButton *quickPayBtn = [ConfigXp buttonWithFrame:CGRectMake(0, 0, scrWidth(), screenScale(45))
                                                title:nil
                                           titleColor:nil
                                                 font:nil
                                      backgroundColor:getColor(@"ffffff")
                                                image:nil];
    [quickPayBtn addTarget:self action:@selector(quickPayBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:quickPayBtn];
    
    UILabel *quickLabel = [ConfigXp labelWithFrame:CGRectZero
                                              text:@"常见问题"
                                         textColor:getColor(@"333333")
                                              font:get4sFont(12)
                                     textAlignment:NSTextAlignmentLeft
                                   backgroundColor:[UIColor clearColor]];
    [quickPayBtn addSubview:quickLabel];
    [quickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).with.offset(screenScale(15));
        make.left.mas_equalTo(self.view).with.offset(screenScale(15));
        
        
    }];
    
    UIImageView *quickImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"turn_black"]];
    [quickPayBtn addSubview:quickImg];
    [quickImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(quickPayBtn.mas_centerY);
        make.right.mas_equalTo(self.view).with.offset(screenScale(-15));
        make.width.mas_equalTo(screenScale(15));
        make.height.mas_equalTo(screenScale(15));
    }];
    
    UIView *threadView = [[UIView alloc]init];
    threadView.backgroundColor = getThreadColor();
    [self.view addSubview:threadView];
    [threadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(quickPayBtn.mas_bottom).with.offset(0);
        make.left.mas_equalTo(self.view).with.offset(0);
        make.width.mas_equalTo(scrWidth());
        make.height.mas_equalTo(screenScale(1));
    }];
    
    ///
    
    UIButton *bankBtn = [ConfigXp buttonWithFrame:CGRectMake(0, screenScale(46), scrWidth(), screenScale(45))
                                            title:nil
                                       titleColor:nil
                                             font:nil
                                  backgroundColor:getColor(@"ffffff")
                                            image:nil];
    [bankBtn addTarget:self action:@selector(bankBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:bankBtn];
    
    UILabel *bankLabel = [ConfigXp labelWithFrame:CGRectZero
                                             text:@"在线客服"
                                        textColor:getColor(@"333333")
                                             font:get4sFont(12)
                                    textAlignment:NSTextAlignmentLeft
                                  backgroundColor:[UIColor clearColor]];
    [bankBtn addSubview:bankLabel];
    [bankLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(threadView.mas_bottom).with.offset(screenScale(15));
        make.left.mas_equalTo(self.view).with.offset(screenScale(15));
        
        
    }];
    
    UIImageView *bankImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"turn_black"]];
    [bankBtn addSubview:bankImg];
    [bankImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(bankBtn.mas_centerY);
        make.right.mas_equalTo(self.view).with.offset(screenScale(-15));
        make.width.mas_equalTo(screenScale(15));
        make.height.mas_equalTo(screenScale(15));
    }];
    
    UIView *threadView2 = [[UIView alloc]init];
    threadView2.backgroundColor = getThreadColor();
    [self.view addSubview:threadView2];
    [threadView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bankBtn.mas_bottom).with.offset(0);
        make.left.mas_equalTo(self.view).with.offset(0);
        make.width.mas_equalTo(scrWidth());
        make.height.mas_equalTo(screenScale(5));
    }];
    
    ///
    
    UIImageView *QQImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"kefu_qq"]];
    [self.view addSubview:QQImg];
    [QQImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).with.offset(screenScale(110));
        make.left.mas_equalTo(self.view).with.offset(screenScale(15));
        make.width.mas_equalTo(screenScale(16));
        make.height.mas_equalTo(screenScale(16));
    }];
    
    UILabel *QQlabel = [ConfigXp labelWithFrame:CGRectZero
                                           text:@"客服QQ："
                                      textColor:getColor(@"666666")
                                           font:get4sFont(13)
                                  textAlignment:NSTextAlignmentLeft
                                backgroundColor:[UIColor clearColor]];
    [self.view addSubview:QQlabel];
    [QQlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).with.offset(screenScale(108));
        make.left.mas_equalTo(self.view).with.offset(screenScale(34));
        
        
    }];
    
    UITextView *QQTextView = [[UITextView alloc]init];
//    QQTextView.backgroundColor = [UIColor redColor];
    QQTextView.editable = NO;
    QQTextView.scrollEnabled = NO;
    QQTextView.text = @"12345678";
    QQTextView.font = get4sFont(11);
    QQTextView.textColor = getMainColor();
    [self.view addSubview:QQTextView];
    [QQTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).with.offset(screenScale(102));
        make.left.mas_equalTo(QQlabel.mas_right).with.offset(screenScale(3));
        make.width.mas_equalTo(screenScale(200));
        make.height.mas_equalTo(screenScale(22));
    }];
    
    QQTextView.text = [_dataDic objectForKey:@"qqNo"];
    
    ///
    
    UIImageView *phoneImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"kefu_dianhua"]];
    [self.view addSubview:phoneImg];
    [phoneImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).with.offset(screenScale(134));
        make.left.mas_equalTo(self.view).with.offset(screenScale(15));
        make.width.mas_equalTo(screenScale(16));
        make.height.mas_equalTo(screenScale(16));
    }];
    
    UILabel *phonelabel = [ConfigXp labelWithFrame:CGRectZero
                                           text:@"客服电话："
                                      textColor:getColor(@"666666")
                                           font:get4sFont(13)
                                  textAlignment:NSTextAlignmentLeft
                                backgroundColor:[UIColor clearColor]];
    [self.view addSubview:phonelabel];
    [phonelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).with.offset(screenScale(134));
        make.left.mas_equalTo(self.view).with.offset(screenScale(34));
        
        
    }];
    
    UIButton *phoneBtn = [ConfigXp buttonWithFrame:CGRectZero
                                             title:nil
                                        titleColor:nil
                                              font:nil
                                   backgroundColor:nil
                                             image:nil];
    [phoneBtn addTarget:self action:@selector(phoneBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:phoneBtn];
    [phoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).with.offset(screenScale(134));
        make.left.mas_equalTo(self.view).with.offset(0);
        make.right.mas_equalTo(self.view).with.offset(0);
        make.height.mas_equalTo(screenScale(22));
    }];
    
    _numLabel = [ConfigXp labelWithFrame:CGRectZero
                                              text:@"13688887777"
                                         textColor:getMainColor()
                                              font:get4sFont(11)
                                     textAlignment:NSTextAlignmentLeft
                                   backgroundColor:[UIColor clearColor]];
    [self.view addSubview:_numLabel];
    [_numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).with.offset(screenScale(134));
        make.left.mas_equalTo(phonelabel.mas_right).with.offset(screenScale(3));
        
        
    }];
    _numLabel.text = [_dataDic objectForKey:@"phoneNo"];
    
}

#pragma mark ------------------ click -------------------

- (void)quickPayBtnClick{
    
    NSLog(@"常见问题");
    
//    zhinanViewController *vc = [[zhinanViewController alloc]init];
//    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)bankBtnClick{
    
    NSLog(@"在线客服");
    
    zaixiankefuTableViewController *vc = [[zaixiankefuTableViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)phoneBtnClick{

    NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",_numLabel.text];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    
}

@end
